package com.tmxk.days01.demo3_pets_wmh;

public class Rabbit extends Pet{
    /**
     * 外貌
     */
    private String appearance;

    public String getAppearance() {
        return appearance;
    }

    public void setAppearance(String appearance) {
        this.appearance = appearance;
    }


    public Rabbit() {}


    public Rabbit(String name) {
        super(name);
    }

    @Override
    public float calRent(int days) {
        return 0;
    }

    public Rabbit(String name, int age, String strain, String appearance) {
        super(name, age, strain);
        this.appearance = appearance;
    }
    public void shout() {
        System.out.println("兔子叫");
    }

    public void run(){
        System.out.println(super.name + "擅长跑");
    }

    // 常识:Object父类equals方法比较的还是内存地址
    // String类重写了Object父类的equals() 方法
    // 模拟String类中equals方法, 重写Rabbit用户自定义类的equals方法
    // instanceof 对象类型引用比较, 判断当前传递的对象引用是否是指定的数据类型
    public boolean equals(Object anObject) {
        if (this == anObject) {
            return true;
        }
        // anObject instanceof Rabbit :判断当前传递到对象引用是否是 Rabbit 类型
        if (anObject instanceof Rabbit) {
            Rabbit rabbit = (Rabbit) anObject;
            if (this.getName().equals(rabbit.getName())
                    && this.getAge() == rabbit.getAge()
                    && this.getStrain().equals(rabbit.getStrain())
                    && this.getAppearance().equals(rabbit.getAppearance())) {
                return true;
            }else{
                return false;
            }
        }
        return false;
    }
}


